package cn.yunhe.controller;

import cn.yunhe.pojo.Orders;
import cn.yunhe.service.IOrdersService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    IOrdersService ordersService;

    @RequestMapping("/queryAll")
    public String queryAll(Model model,
                           @RequestParam(defaultValue = "1") Integer pageIndex,
                           @RequestParam(defaultValue = "3") Integer pageSize){
        List<Orders> ordersList = ordersService.queryAll(pageIndex, pageSize);
        PageInfo<Orders> ordersPageInfo = new PageInfo<Orders>(ordersList);
        model.addAttribute("pageInfo", ordersPageInfo);
        return "order-list";
    }

    @RequestMapping("/query")
    public String queryOrdersById(Model model,String id){
        Orders orders = ordersService.queryOrdersById(id);
        model.addAttribute("orders",orders);
        return "order-info";
    }
}
